package com.nkym.exception;/*
 * @ClassName GlobalExceptionHandler
 * @Desc TODO
 * @Author 19637
 * @Date 2023/4/19 20:26
 * @Version 1.0
 */

import com.nkym.common.BaseResponse;
import com.nkym.utils.ResultUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletResponse;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
    @ExceptionHandler({
            Exception.class
    })
    public BaseResponse handlerException(Exception e, HttpServletResponse response){
        log.error("{}",e);

        return ResultUtil.fail(null,"服务器错误");
    }  @ExceptionHandler({
            BusinessException.class
    })
    public BaseResponse handlerBusinessException(BusinessException e, HttpServletResponse response){
        log.error("{}",e);
        return ResultUtil.fail(e.getCode(),e.getMessage());
    }
}
